﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using M7;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace C7
{
    
    public static class Booking
    {
        public static void Add(ref NBooking obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumBooking.BookingAdd;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
        public static void Cancel(ref NBooking obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumBooking.BookingCancel;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
        public static void Delete(ref NBooking obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumBooking.BookingDelete;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
        public static void Edit(ref NBooking obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumBooking.BookingEdit;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }
    
    public static class Customer
    {
        public static void SignUp(ref NCustomer obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumCustomer.CustomerSignUp;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void SignIn(ref NCustomer obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            //TcpConnection con = new TcpConnection();
            SendMsg.enumMethod = enumCustomer.CustomerSignIn;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void SignOut(ref NCustomer obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumCustomer.CustomerSignOut;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void Delete(ref NCustomer obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumCustomer.CustomerDelete;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void GetInfo(ref NCustomer obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumCustomer.CustomerGetInfo;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }
    
    public static class Favorite
    {
        public static void Add(ref NFavorite obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumFavorite.FavoriteAdd;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
        public static void Delete(ref NFavorite obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumFavorite.FavoriteDelete;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }

    public static class Feedback
    {
        public static void Add(ref NFeedback obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumFeedback.FeedbackAdd;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }
    
    public static class Menus
    {
        public static List<NMenus> MenusList = new List<NMenus>();
        public static int currentMenuID = 0;
        public delegate void delShowMenus();
        private static void ShowMenus()
            {
                if (Info.module is MenuModule)
                {
                    foreach (var mozza in Menus.MenusList)
                    {
                        (Info.module as MenuModule).lbCategories.Items.Add(mozza.MenuName);
                    }
                }
            }
        public static delShowMenus del = new delShowMenus(ShowMenus);
        public static void Search()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumMenus.MenusSearch;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }
    
    public static class MenuItem
    {
        public static List<NMenuItem> MenuItemsList = new List<NMenuItem>();

        private delegate void delShowMenuItems(IEnumerable<NMenuItem> query);
        private delegate void delClear();
        private static void Show(IEnumerable<NMenuItem> query)
        {
            if (Info.module is MenuModule)
            {
                (Info.module as MenuModule).lbMenuItems.ItemsSource = query;
            }
        }
        private static void Clear()
        {
            if (Info.module is MenuModule)
            {
                (Info.module as MenuModule).lbMenuItems.Items.Clear();
            }
        }
        public static void ShowMenuItems(int menuID)
        {
            delShowMenuItems del = new delShowMenuItems(Show);
            delClear delclear = new delClear(Clear);
            while (true)
            {
                if (MenuItemsList != null)
                {
                    var query = from item in MenuItemsList
                                where item.MenuID == menuID
                                select item;
                    (Info.module as MenuModule).lbMenuItems.Dispatcher.Invoke(del, new object[] { query });
                    break;
                }
                else
                {
                    Thread.Sleep(50);
                }
            }
        }
        public static void Search()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumMenuItem.MenuItemsSearch;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }

    public static class Order
    {
        public static List<NMenuItem> lstOrders = new List<NMenuItem>();
        public static void Add(ref NOrder obj)
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumOrder.OrderAdd;
            SendMsg.obj = obj;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void NotPaid()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumOrder.OrderGet;
            SendMsg.obj = Info.current.CustomerID;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }

    public static class PersonalizationClass
    {
        public static List<string> lstGenre;
        public delegate void delShowGenres();

        private static void ShowGenres()
        {
            if (Info.module is PersonalizationModule)
            {
                foreach (var genre in lstGenre)
                {
                    (Info.module as PersonalizationModule).lbMusicGenre.Items.Add(genre);
                }
            }
        }

        public static void GetGenres()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumPersonalization.GetGenres;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
        public static delShowGenres del = new delShowGenres(ShowGenres);


        public static void GetTVChannels()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumPersonalization.GetTVChannels;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

        public static void GetAC()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumPersonalization.GetACTemp;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }

    }

    public static class AdminTools
    {
        public static void SetModules(ref Dictionary<enumModules, bool> dic)
        {
            foreach (var module in dic)
            {
                switch (module.Key)
                {
                    case enumModules.Chat:
                        {
                            Properties.Settings.Default.ChatModule = module.Value;
                            break;
                        }
                    case enumModules.CheckOut:
                        {
                            Properties.Settings.Default.CheckOutModule = module.Value;
                            break;
                        }
                    case enumModules.Games:
                        {
                            Properties.Settings.Default.GamesModule = module.Value;
                            break;
                        }
                    case enumModules.Internet:
                        {
                            Properties.Settings.Default.InternetModule = module.Value;
                            break;
                        }
                    case enumModules.Memoire:
                        {
                            Properties.Settings.Default.MemoireModule = module.Value;
                            break;
                        }
                    case enumModules.Personalization:
                        {
                            Properties.Settings.Default.PersonalizationModule = module.Value;
                            break;
                        }
                    case enumModules.Menu:
                        {
                            Properties.Settings.Default.MenuModule = module.Value;
                            break;
                        }
                }
            }
            Properties.Settings.Default.Save();
        }

        public static void GetModules()
        {
            Msg SendMsg = new Msg(Properties.Settings.Default.Port, Properties.Settings.Default.TableID);
            SendMsg.enumMethod = enumAdminTools.DisableModule;
            TcpConnection.SendingQueue.Enqueue(SendMsg);
        }
    }
}
